/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Phan1.LietKe.PPSinh;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

/**
 *
 * @author Giaotk
 */
public class DayNhiPhanN {

    public DayNhiPhanN() {
        DoIt();
    }

    private void DoIt() {

        //Initializion
        int max = 100;
        int[] x = new int[max];
        int k, n;
        StringBuilder sb = new StringBuilder();
        String internalPath = this.getClass().getName().replace(".", File.separator);
        String externalPath = System.getProperty("user.dir") + File.separator + "src";
        String workDir = externalPath + File.separator + internalPath.substring(0, internalPath.lastIndexOf(File.separator));

        String inputPath = workDir + "\\DayNhiPhanN\\input.txt";
        String outputPath = workDir + "\\DayNhiPhanN\\output.txt";
        String line = "";
        StringBuilder read = new StringBuilder();
        try {
            FileReader filereader = new FileReader(inputPath);
            BufferedReader bufferreader = new BufferedReader(filereader);
            while ((line = bufferreader.readLine()) != null) {
                read.append(line);
                read.append("\n");
            }
            bufferreader.close();
        } catch (FileNotFoundException ex) {
            System.out.println("Unable to open file " + inputPath);
        } catch (IOException ex2) {
            System.out.println("Error when reading file " + inputPath);
        }finally{
            
        }

        n = Integer.parseInt(read.toString().trim());
        k = n - 1;
        for (int i = 0; i < max; i++) {
            x[i] = 0;
        }

        while (k > -1) {
            //In chuoi khoi tao
            for (int i = 0; i < n; i++) {
                sb.append(x[i]);
            }
            sb.append("\n");
            //Lui mang toi vi tri x[i]=0 hoac toi gia tri dich
            k = n - 1;
            while (k > -1 && x[k] == 1) {
                k--;
            }
            if (k > -1) {
                x[k] = 1;
                for (int i = k + 1; i < n; i++) {
                    x[i] = 0;
                }
            }

        }
        
        
        try{
            FileWriter fw = new FileWriter(outputPath);
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write(sb.toString().trim());
            bw.close();
        }catch(IOException ex){
            System.out.println("Loi doc file "+outputPath);
        }
        
        System.out.print(sb.toString());
        System.out.println(internalPath);
        System.out.println(externalPath);
        System.out.println(workDir);


    }
}
